<!--
 * @Date: 2024-10-23 16:57:16
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-10-23 16:57:19
 * @Description: 
-->
<template>
  <FpRender
    ref="formRenderRef"
    :="formRenderAttrs"
    :formData="formData"
    @loaded="formRenderLoaded"
  />
</template>

<script setup>
import { reactive, ref } from 'vue';
import { FpRender } from '@fp';


const props = defineProps({
  type: { type: String, default: 'expert' },
  autoLoad: { type: Boolean, default: false },
  formType: { type: String, default: 'expert' },
  formCode: { type: String },
  formData: { type: Object, default: () => ({}) }
})

const formRenderRef = ref()
const formRenderAttrs = reactive({
  ...props
})

const loadData = () => {
  nextTick(() => { formRenderRef.value.loadFormInfo() })
}

const getData = async (validate=true) => {
  const { validateFormData, getRenderFormData } = formRenderRef.value;
  const valid = await validateFormData();
  if (!valid) return
  try {
    const resData = await getRenderFormData()
    const signature = {
      label: '专家签名',
      value: resData.slotsData.signature || '',
      dataField: 'PRD_EXPERT_OTHER.SIGNATURE',
    }
    return [ ...resData.dataArray, signature ]
  } catch(error) {
    console.error(error)
  }
}
const formRenderLoaded = () => {
  
}

loadData()

defineExpose({
  getData
})

</script>

<style lang="scss" scoped>

</style>